package com.example.demo.controller;

import com.example.demo.common.BaseResponse;
import com.example.demo.common.ErrorCode;
import com.example.demo.common.ResultUtils;
import com.example.demo.exception.ThrowUtils;
import com.example.demo.model.dto.UserLoginRequest;
import com.example.demo.model.dto.UserRegisterRequest;

import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("health")
    public BaseResponse<?> health(){
        return ResultUtils.success("ok");
    }

    @GetMapping("register")
    public BaseResponse<String> register(UserRegisterRequest userRegisterRequest) {
        ThrowUtils.throwIf(userRegisterRequest == null, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success("ok");
    }
    
    @GetMapping("login")
    public BaseResponse<?> login(UserLoginRequest userLoginRequest) {
        ThrowUtils.throwIf(userLoginRequest == null, ErrorCode.PARAMS_ERROR);
        return userService.login(userLoginRequest);
    }
    
}
